﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.ViewModels.ParticipantFieldViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ListofParticipants
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="../../Scripts/EditParticipant.js"></script>
    <div class="pageHeadingContainer"><h2 class="pageHeading">List of Participants - <%=Model.poll.name %></h2></div>
    <div id="contentContainer">
    <p>
        <%= Html.ActionLink("Polls > ", "Index", "Poll", null, new { @class = "breadcrumb" })%><%= Model.poll.name %></p>
    <div id="pageMenuContainer">
        <ul id="pageMenu">
            <li>
                <%= Html.ActionLink("Details", "Questions", new { pollID = Model.poll.pollID }) %></li>
            <li>
                <%= Html.ActionLink("Run", "SetSession", new { pollID = Model.poll.pollID }) %></li>
            <li>
                <%= Html.ActionLink("Test", "Test", new { pollID = Model.poll.pollID }) %></li>
            <li>
                <%= Html.ActionLink("Reports", "Reports", new { pollID = Model.poll.pollID }) %></li>
            <li>
                <%= Html.ActionLink("Manage Hierarchy", "EntityHierarchy", new { pollID = Model.poll.pollID }) %></li>
        </ul>
    </div>
    <table class="questions"><thead><tr><th>Device ID</th><th>Username</th>
    <th>Email</th><th>Type of User</th><th>Delete</th></tr></thead>
    <tbody>
    <% var order = Model.poll.participants.Where(p => p.type == Model.generic).OrderBy(p => p.linkedUser.UserName).
           Concat(Model.poll.participants.Where(p=>p.type==Model.web).OrderBy(p=>p.linkedUser.UserName)).
           Concat(Model.poll.participants.Where(p=>p.type==Model.keypad).OrderBy(p=>p.deviceID));
        foreach (var participant in order)
       {
           if (participant.type == Model.type("Keypad"))
           {
               %><tr><td><%=participant.deviceID%></td><td></td><td></td><td>Keypad User</td>
           <%}
           else if (participant.type == Model.type("Generic"))
           {
               %><tr><td></td><td><%=participant.linkedUser.UserName%></td><td></td><td>Generic User</td>
           <%}
           else
           {%><tr><td><%=participant.deviceID%></td><td><%=participant.linkedUser.UserName%></td><td><%=participant.linkedUser.Email%></td>
           <td>Web User</td>
           <%} using (Ajax.BeginForm("Delete", new 
             { participantID = participant.participantID , pollID = Model.poll.pollID }, new AjaxOptions{UpdateTargetId = "message", OnSuccess="deleted"}))
           { %>
                    <% Html.ValidationSummary(true); %>
                    <td><input type="submit" value="Delete" /></td></tr>
                <%}
       }
     %>
     </tbody></table>
     <% using (Html.BeginForm("AddWeb", "Participant", new {  pollID = Model.poll.pollID, pollName = Model.poll.name }, FormMethod.Post))
       { %>
    <% Html.ValidationSummary(true); %>
    <input type="submit" value="Add Participant" />
    <% } %>
    <input type="hidden" id="message" />
    <input id="pollid" value="<%=Model.poll.pollID %>" type="hidden" />
    <input id="pollname" value="<%=Model.poll.name %>" type="hidden" />
    </div>   
</asp:Content>
